package com.hhkj.admin.order.common.component.validator;

import com.hhkj.admin.course.domain.CourseBankType;
import com.hhkj.admin.order.common.exception.InvalidOrderItemException;
import com.hhkj.admin.order.domain.OrderItem;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;
import java.util.Map;

@AllArgsConstructor
@Data
public class DefaultBankTypeValidateStrategy extends BaseOrderItemValidateStrategy{

    /** （科目父类id-科目默认题库）map映射表 **/
    private Map<Long, List<CourseBankType>> courseParentIdBankMap;

    private Map<Long, Long> courseIdParentIdMap;

    /**
     * 校验默认题库
     * @param orderItem
     * @return
     * @throws InvalidOrderItemException
     */
    @Override
    public boolean validate(OrderItem orderItem) throws InvalidOrderItemException {
        Long parentId = courseIdParentIdMap.get(orderItem.getCourseId());
        List<CourseBankType> courseBankTypeList = courseParentIdBankMap.get(parentId);
        Long defaultCourseBankTypeId = OrderItemValidator.isValidDefaultCourseBank(courseBankTypeList);
        orderItem.setCourseBankTypeId(defaultCourseBankTypeId);
        return true;
    }
}
